home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000135_icon-group-sender _Tue Jun 15 16:21:59 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA12496
  4.     for icon-group-addresses; Tue, 15 Jun 1999 16:20:36 -0700 (MST)
  5. Message-Id: <199906152320.QAA12496@baskerville.CS.Arizona.EDU>
  6. Delivered-To: icon-group@silliac.cs.arizona.edu
  7. Date: Tue, 15 Jun 1999 16:41:16 -0300 (ADT)
  8. From: Larry Bezeau <bezeau@unb.ca>
  9. X-Sender: bezeau@sol.sun.csd.unb.ca
  10. To: Icon list <icon-group@optima.CS.Arizona.EDU>
  11. Subject: Problems with noncase.icn from program library
  12. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  13. Status: RO
  14.  
  15.       I have recently been using the Icon program library for
  16. dealing with strings using regular expressions and have run into
  17. a few problems, not with the regular expression procedures
  18. themselves, but with a set of procedures called "noncase.icn",
  19. used for case insensitive searching with regular expressions.
  20. An example follows.
  21.  
  22.       The following procedure from noncase.icn is intended to
  23. duplicate find in a case insensitive way.
  24.  
  25. procedure c_find(s1,s2,i1,i2)
  26.   local scanPos,endPos
  27.   scanPos := match("",s2,i1,i2)
  28.   endPos := many(&cset,s2,i1,i2)
  29.   suspend scanPos - 1 + find(map(s1),
  30.       map((if \s2 then s2 else &subject)[scanPos:endPos]))
  31. end
  32.  
  33. A problem occurs if the subject string is empty.  In this case,
  34. the statement to set the value of endPos fails leaving endPos
  35. undefined.  The last statement produces a program error when
  36. an attempt is made to extract a substring of &subject with
  37. one index having the null value.  The analogous built-in function
  38. (find) simply fails under the same circumstances.
  39.  
  40.         My solution was to replace the fourth line in the procedure
  41. with
  42.           endPos := (many(&cset,s2,i1,i2) | scanPos)
  43.  
  44. which at least prevents the program error.  I have not tested this
  45. rigorously.  Can anyone see problems with this or make other
  46. suggestions?
  47.                                       Larry   Bezeau@UNB.Ca
  48.  
  49.